<!DOCTYPE html>
<html>
<head>
    <title>枣阳市第二人民医院管理系统</title>
	<meta charset="UTF-8">
   <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <link rel="stylesheet" type="text/css" href="../Js/disk/style.css">
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/disk/longbow.js"></script>
    <style type="text/css">
        body {
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }

        .form-signin {
            max-width: 300px;
            padding: 19px 29px 29px;
            margin: 0 auto 20px;
            background-color: #fff;
            border: 1px solid #e5e5e5;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
            -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
            -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
            box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
        }

        .form-signin .form-signin-heading,
        .form-signin .checkbox {
            margin-bottom: 10px;
        }

        .form-signin input[type="text"],
        .form-signin input[type="password"] {
            font-size: 16px;
            height: auto;
            margin-bottom: 15px;
            padding: 7px 9px;
        }


    </style>  
</head>
<body>
<div class="container">

    <div class="form-signin">
        <h2 class="form-signin-heading">&nbsp;&nbsp;&nbsp;登录系统</h2>
        <input type="text" name="username" class="input-block-level" value="最高指挥官" placeholder="账号">
        <input type="password" name="password" class="input-block-level" value="abc123." placeholder="密码">
        <div class="container-fluid" style="margin-bottom: 15px; padding-left: 0; padding-right: 0; height: 200px;">
             <div id="captcha"></div>
        </div>
       
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-large btn-primary" id="login-btn" type="button">登录</button></p>
        <span id="loginTips" style="color:red;display: none"></span>
    </div>

</div>
<script>
    let firsetverify = true;

    $(function (){
        // 回调地址
        let callBackUrL = document.location.toString().GetValue("callBackUrL");
        let username = document.location.toString().GetValue("username");
        if(username == undefined || username == '' || username == 'null'){}else{
            // $("input[name='username']").val(username)
        }

        $("#login-btn").on("click", function(){
            layer.msg("请先完成安全验证", function(){})
        })

        $('#captcha').sliderCaptcha({
            repeatIcon: 'fa fa-redo',
            setSrc: function () {
                if(firsetverify){
                    firsetverify = false;
                }else{
                    layer.msg("验证失败，请重试", function(){})
                }
                return ''; },
            onSuccess: function () {
                layer.msg("完成安全验证");
                $(".slider").css("pointer-events","none")
                $("#login-btn").off("click");
                $("#login-btn").on("click", function(){
                    layer.load(0)
                    var uLoginName = $("input[name='username']").val()
                    var uPassword = $("input[name='password']").val()
                    $.ajax({
                        type: "POST",
                        url: origin + "/access/login",
                        data: {uLoginName:uLoginName,uPassword:uPassword},
                        dataType: "json",
                        xhrFields: {
                            withCredentials: true
                        },
                        crossDomain: true,
                        success: function (data) {
                            layer.closeAll()
                            if (data.code == 200){
                                layer.msg("登陆成功")
                                setTimeout(function(){
                                    // 跳回原地址
                                    window.location.href = callBackUrL;
                                },300)
                            }else {
                                $("input[name='username']").on("click", function(){
                                    window.location.href = "login.html?username=" + $("input[name='username']").val().trim()
                                        + "&callBackUrL=" + callBackUrL;
                                })
                                $("input[name='password']").on("click", function(){
                                    window.location.href = "login.html?username=" + $("input[name='username']").val().trim()
                                        + "&callBackUrL=" + callBackUrL;
                                })
                                layer.msg(data.msg,function(){})
                                $("#loginTips").text(data.msg)
                                $("#loginTips").show()
                            }
                        },
                        complete: function (xhr, status) {
                            $.removeCookie("jwtToken",{path:'/'})
                            jwtToken = xhr.getResponseHeader("jwt");
                            $.cookie('jwtToken', jwtToken, { expires: 7, path: '/' });
                        }
                    })
                })
            }
        });

    })
    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }
</script>
</body>
</html>
